// See https://aka.ms/new-console-template for more information
//确定初始位置
int x = 7, y = 0, month = 1;
Console.SetCursorPosition(x, y);
for (month = 1; month <= 12; month++)
{//输出月份
    Console.WriteLine("{0}月", month);
 //换行 输出星期
    Console.SetCursorPosition(x - 7, y + 1);
    Console.WriteLine("日  一  二  三  四  五  六");
 //输出每一天
    if (month <= 12)
    { 
        DateTime Day = new DateTime(2022, month, 1);
        //判断当月有多少天
        int day=DateTime.DaysInMonth(Day.Year, Day.Month);
        //判断当月1号是星期几
        int m = (int)Day.DayOfWeek;
        Console.SetCursorPosition(x - 7 + 4 * m, y + 2);
        //输出剩下的天数
        int n = 0;
        for (int i = 1; i <= day; i++)
        {

            Console.Write("{0,2}", i);
            Console.Write(new string(' ', 2));
            DateTime dt = new DateTime(2022, month, i);
            //每逢周六换行
            if (dt.DayOfWeek == DayOfWeek.Saturday) 
            { n++; Console.SetCursorPosition(x - 7, y + 2 + n); }
        }
        //每三个月换行
        if (month % 3 != 0)
            x += 32;
        else { x = 7; y += 12; }
        Console.SetCursorPosition(x, y);
    }
}
Console.ReadLine();